<?php
namespace App\Http\Controllers\MobileWeb;

use App\Http\Controllers\WebController;
use App\Http\Controllers\Business\App\PublicBusiness;
use App\Http\Controllers\Business\App\Today\Today;
use App\Http\Controllers\Business\App\Common\Common;
use App\Http\Controllers\Business\App\Auth\AppAuth;
use App\Http\Controllers\Business\App\MyCenter\MyCenter;
use App\Http\Controllers\Business\App\Statistic\StatisticManagement;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Auth;

class IndexController extends WebController
{
    //获取注册验证码; type属性：1用户端，2商户端，3后台; mode: 1短信验证码，2语音验证码
    public function getCaptcha() {
        $mobile = $this->request->get('mobile');
        if($this->request->has('mode')) {
            $mode = $this->request->get('mode');
        } else {
            $mode = '1';
        }
        if($this->request->has('type')) {
            $type = $this->request->get('type');
        } else {
            $type = '1';
        }
        $mobile = trim($mobile);
        $result = AppAuth::getCode($mobile, $type, $mode);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $message = $result['message'];
        return $this->responseSuccessMessage($message);
    }
    //验证手机验证码（注册，绑定手机号）
    public function verifyCaptcha() {
        $mobile = $this->request->get('mobile');
        $code = $this->request->get('code');
        $mobile = trim($mobile);
        $result = AppAuth::validataSmsCode($mobile, $code);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //地推获取验证码，并且检测用户是否注册过
    public function getCaptchaAndJudgeRegister() {
        $mobile = $this->request->get('mobile');
        if($this->request->has('mode')) {
            $mode = $this->request->get('mode');
        } else {
            $mode = '1';
        }
        if($this->request->has('type')) {
            $type = $this->request->get('type');
        } else {
            $type = '1';
        }
        $mobile = trim($mobile);
        $result = AppAuth::getCodeAndJudgeRegister($mobile, $type, $mode);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        return $this->responseSuccessMessage($result['message']);
    }
    //注册时  输入手机号码
    public function login() {
        if($this->request->has('inviterid')) {
            $inviterId = $this->request->get('inviterid');
            return response()->make(view('mobile.login_mobile'))->withCookie(cookie('inviterid', $inviterId, 10));
        } else {
            return view('mobile.login_mobile');
        }
    }
    //注册时 输入验证码, 用户协议同意
    public function loginCode() {
        if(!$this->request->has('mobile')) {
            return view('mobile.login_mobile');
        }
        $mobile = $this->request->get('mobile');
        $isFirstLoginResult = AppAuth::isFirstLogin($mobile);
        if(($isFirstLoginResult['status'] == 'success')) {
            if(isset($isFirstLoginResult['data']['islogin']) && ($isFirstLoginResult['data']['islogin']) == '0') {
                //是否第一次登录，如果是跳转到用户协议, 如果阅读了用户协议，跳转到发送短信
                if(!$this->request->has('useragreement') || ($this->request->get('useragreement') != 1)) {
                    $data = ['mobile' => $mobile];
                    return view('mobile.user_agreement', $data);
                }
            }
        }
        //发送验证码
        $result = AppAuth::getCode($mobile, '1', '1');
        if($result['status'] == 'failed') {
            $message = $result['message'];
        } else {
            $message = '';
        }
        $data = [
            'mobile' => $mobile,
            'message' => $message
        ];
        return view('mobile.login_code', $data);
    }
    //注册提交数据
    public function submitLoginData() {
        $mobile = $this->request->get('mobile');
        $code = $this->request->get('code');
        $this->request->session()->get('nickname');
        $this->request->session()->get('headimgurl');
        $this->request->session()->get('sex');
        $avatar = $this->request->session()->get('headimgurl');
        $nickName = $this->request->session()->get('nickname');
        $openId = $this->request->session()->get('openid');
        $type = '0';
        $channel = '微信公众号';
        $result = AppAuth::registerOrLogin($mobile, $code, $avatar, $nickName, $openId, $type, $channel);
        if($result['status'] == 'failed') {
            $data = [
                'mobile' => $mobile,
                'message' => $result['message']
            ];
            return view('mobile.login_code', $data);
        } else {
            $data = $result['data'];
            $userId = $data['userid'];
            //登录
            $result = Auth::loginUsingId($userId);
            //推荐有奖处理

            return redirect()->to('/mobile/mycenter/index');
        }
    }
    //注销
    public function logout() {
        Auth::logout();
        if(Cookie::has('cityid')) {
            $cityId = Cookie::get('cityid');
            $cityName = Cookie::get('cityname');
            return redirect()->to('/mobile/index?cityid=' . $cityId . "&cityname=" . $cityName);
        } else {
            return redirect()->to('/mobile/position');
        }
    }
    //首页
    public function index() {
        //获取城市id
        if($this->request->has('cityid')) {
            $cityId = $this->request->get('cityid');
            $cityName = $this->request->get('cityname');
        } else {
            if (Cookie::has('cityid')) {
                $cityId = Cookie::get('cityid');
                $cityName = Cookie::get('cityname');
            } else {
                //获取城市id
                return redirect()->to('/mobile/position');
            }
        }
        if(Cookie::has('mylongitude')) {
            $myLongitude = Cookie::get('mylongitude');
        } else {
            $myLongitude = '';
        }
        if(Cookie::has('mylatitude')) {
            $myLatitude = Cookie::get('mylatitude');
        } else {
            $myLatitude = '';
        }
        $bannerResult = Today::getIndexBanner($cityId);
        //$categoryResult = Today::getIndexClass();
        $nightResult = Today::getIndexOccur($cityId);
        $data = [
            'banner' => $bannerResult['data'],
            //'category' => $categoryResult['data'],
            'occur' => $nightResult['data']
        ];
        //获取商家列表
        $event = 'today';

        $parameter = [];
        $sort = 'distance';
        $shopListResult = PublicBusiness::shopList($cityId,$event,$myLongitude,$myLatitude,$parameter,$sort);
        if($shopListResult['status'] == 'failed') {
            $data['shoplists'] = [];
        } else {
            $data['shoplists'] = $shopListResult['data'];
        }
        $data['page'] = 1;
        $data['cityid'] = $cityId;
        $data['cityname'] = str_replace("市", "", $cityName);
        $data['mylongitude'] = $myLongitude;
        $data['mylatitude'] = $myLatitude;
        //写登录日志
        $ip = $this->request->ip();
        $userAgent = $this->request->header('user-agent');
        StatisticManagement::addUserLoginAfterInfo('','index',$userAgent,$ip);

        return response()->make(view('mobile.today.index', $data))->withCookie(cookie('cityid', $cityId))
            ->withCookie(cookie('cityname', $cityName));
    }
    //城市定位
    public function position() {
        $ip = $this->request->ip();
        $result = Common::getCityIdByIp($ip);
        if ($result['status'] == 'failed') {
            $cityId = 1;
            $status = 1;
            $cityName = '南昌市';
        } else {
            $cityId = $result['data']['cityid'];
            $status = $result['data']['status'];
            $cityName = $result['data']['cityname'];
        }
        //TODO 最近浏览的城市
        if(Cookie::has('mycities')) {
            $myCities = Cookie::get('mycities');
        } else {
            $myCities = [];
        }
        $cityList = [
            'cityid' => $cityId,
            'cityname' => $cityName,
        ];
        if(!in_array($cityList, $myCities)) {
            array_push($myCities, $cityList);
        }
        $citiesResult = Common::getHavingShopCities();
        if($citiesResult['status'] == 'failed') {
            return view('errors.404');
        }
        $cityLists = $citiesResult['data'];
        $data = [
            'cityid' => $cityId,
            'cityname' => $cityName,
            'status' => $status,
            'mycitylists' => $myCities,
            'citylists' => $cityLists
        ];
        return response()->make(view('mobile.today.position', $data))->withCookie(cookie('cityid', $cityId))
                ->withCookie(cookie('cityname', $cityName))->withCookie(cookie('mycities', $myCities));
    }
    //经纬度
    public function longitudeAndLatitude() {
        $longitude = $this->request->get('longitude');
        $latitude = $this->request->get('latitude');
        if($latitude && $longitude) {
            return response()->json(['status' => 'success'])->withCookie(cookie('mylongitude', $longitude))
                ->withCookie(cookie('mylatitude', $latitude));
        } else {
            return response()->json(['status'=>'success']);
        }
    }
    //切换城市
    public function switchCity() {
        $cityId = $this->request->get('cityid');
        $cityName = $this->request->get('cityname');
        //TODO 最近浏览的城市
        if(Cookie::has('mycities')) {
            $myCities = Cookie::get('mycities');
        } else {
            $myCities = [];
        }
        $cityList = [
            'cityid' => $cityId,
            'cityname' => $cityName,
        ];
        if(!in_array($myCities, $cityList)) {
            array_push($myCities, $cityList);
        }
        $lists = [];
        $count = count($myCities);
        if($count >= 3){
            for($i = $count-3; $i < $count; $i++) {
                array_push($lists, $myCities[$i]);
            }
        } else {
            $lists = $myCities;
        }
        return redirect()->to('/mobile/index?cityid=' . $cityId ."&cityname=".$cityName)->withCookie(cookie('cityid', $cityId))
            ->withCookie(cookie('cityname', $cityName))->withCookie(cookie('mycities', $lists));
    }
    //今日
    public function today() {
        //获取城市id
        $cityInfo = $this->getCityAndLongitudeAndLatitude();
        $cityId = $cityInfo['data']['cityid'];
        $myLongitude = $cityInfo['data']['mylongitude'];
        $myLatitude = $cityInfo['data']['mylatitude'];
        if($this->request->has('classname')) {
            $className = $this->request->get('classname');
        } else {
            $className = '全部';
        }
        if($this->request->has('areaname')) {
            $areaName = $this->request->get('areaname');
        } else {
            $areaName = '全部';
        }
        //商家一级，二级分类
        $categoryResult = Common::getClass();
        if($categoryResult['status'] == 'failed') {
            return view('errors.404');
        }
        $categoryLists = $categoryResult['data'];
        //城市区县，商圈
        $areaResult = Common::getDistrictAndBusinessArea($cityId);
        if($areaResult['status'] == 'failed') {
            return view('errors.404');
        }
        $areaLists = $areaResult['data'];
        $today = date('Y-m-d');
        //获取商家列表
        $event = 'today';
        $parameter = [];
        if($this->request->has('classid')) {
            $classId = $this->request->get('classid');
        } else {
            $classId = '';
        }
        if($this->request->has('isfirstclass') && !empty($classId)) {
            $isFirstClass = $this->request->get('isfirstclass');
            if($isFirstClass == '1') {
                $parameter['firstclassid'] = $classId;
            } else {
                $parameter['secondclassid'] = $classId;
            }
        }
        if($this->request->has('districtid')) {
            $parameter['districtid'] = $this->request->get('districtid');
        }
        if($this->request->has('businessareaid')) {
            $parameter['businessareaid'] = $this->request->get('businessareaid');
        }
        if($this->request->has('sort')) {
            $sort = $this->request->get('sort');
        } else {
            $sort = 'distance';
        }
        $shopListResult = PublicBusiness::shopList($cityId,$event,$myLongitude,$myLatitude,$parameter,$sort);
        if($shopListResult['status'] == 'failed') {
            $shopLists = [];
        } else {
            $shopLists = $shopListResult['data'];
        }
        $data = [
            'classname' => $className,
            'areaname' => $areaName,
            'categorylists' => $categoryLists,
            'arealists' => $areaLists,
            'shoplists' => $shopLists,
            'cityid' => $cityId,
            'mylongitude' => $myLongitude,
            'mylatitude' => $myLatitude,
            'today' => $today,
        ];
        return view('mobile.today.today', $data);
    }
    //商家列表
    public function shopList() {
        if(Cookie::has('cityid')) {
            $cityId = Cookie::get('cityid');
        } else {
            if($this->request->has('cityid')) {
                $cityId = $this->request->get('cityid');
            } else {
                return redirect()->to('/mobile/position');
            }
        }
        if($this->request->has('mylongitude')) {
            $myLongitude = $this->request->get('mylongitude');
        } else {
            if (Cookie::has('mylongitude')) {
                $myLongitude = Cookie::get('mylongitude');
            } else {
                $myLongitude = '';
            }
        }
        if($this->request->has('mylatitude')) {
            $myLatitude = $this->request->get('mylatitude');
        } else {
            if (Cookie::has('mylatitude')) {
                $myLatitude = Cookie::get('mylatitude');
            } else {
                $myLatitude = '';
            }
        }
        $page = $this->request->get('page');
        $event = 'today';
        $parameter=[];
        $sort='commentscore';
        $result = PublicBusiness::shopList($cityId, $event, $myLongitude, $myLatitude, $parameter, $sort);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $message = '获取信息成功';
        $data = $result['data'];
        $data['page'] = $page;
        return $this->responseSuccess($message, $data);
    }
    //获取商家详情
    public function getShopDetail() {
        $cityId = $this->request->get('cityid');
        $myLongitude = $this->request->get('mylongitude');
        $myLatitude = $this->request->get('mylatitude');
        $shopId = $this->request->get('shopid');
        if(!$shopId){
            return view('errors.404');
        }
        $shopDetailResult = PublicBusiness::shopDetails($shopId);
        if($shopDetailResult['status'] == 'failed') {
            return view('errors.404');
        }
        $shopDetail = $shopDetailResult['data'];
        $data = $shopDetail;
        $data['payinfo'] = $shopDetail['payinfo'];
        $data['invoice'] = $shopDetail['invoice'];
        $data['content'] = $shopDetail['content'];
        $data['tips'] = $shopDetail['tips'];
        $data['photoarray'] = $shopDetail['photos'];
        $data['goodphotoarray'] = $shopDetail['goodsphotos'];
        $data['cityid'] = $cityId;
        $data['mylongitude'] = $myLongitude;
        $data['mylatitude'] = $myLatitude;
        $data['shopid'] = $shopId;
        //$userId = Auth::id();
        if(Auth::id()) {
            $userId = Auth::id();
            $collectionResult = MyCenter::isCollection($userId, $shopId);
            $data['collectionstatus'] = $collectionResult['status']; //success or failed
            $subscriptionResult = MyCenter::isSubscription($userId, $shopId);
            $data['subscriptionstatus'] = $subscriptionResult['status']; //success or failed
            $data['auth'] = 1;
        } else {
            $data['collectionstatus'] = 'failed';
            $data['subscriptionstatus'] = 'failed';
            $data['auth'] = 0;
        }
        return view('mobile.today.shop_detail', $data);
    }
    //大图模式
    public function bigPicture() {
        if(!$this->request->has('shopid')) {
            return view('errors.404');
        }
        $shopId = $this->request->get('shopid');
        if($this->request->has('page')) {
            $page = $this->request->get('page');
        } else {
            $page =1;
        }
        $result = PublicBusiness::shopDetails($shopId);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $data = $result['data'];
        $title = $data['name'];
        $logo = $data['logo'];
        $photos = $data['photos'];
        $goodsphotos = $data['goodsphotos'];
        $returnData = [
            'page' => $page,
            'logo' => $logo,
            'title' => $title,
            'photos' => $photos,
            'goodsphotos' => $goodsphotos
        ];
        return view('mobile.today.big_picture', $returnData);
    }
    //翻倍日历
    public function shopEvent() {
        $shopId = $this->request->get('shopid');
        $result = PublicBusiness::doubleCalendarList($shopId);
        $data = $result['data'];
        $lists = [];
        $today = date('Y-m-d');
        foreach($data as $list) {
            $event = date('Y-m-d', strtotime($list['event']));
            if($event < $today) {
                continue;
            }
            array_push($lists, $event);
        }
        return view('mobile.today.calendar', ['lists'=>json_encode($lists)]);
    }
    //商家评论列表
    public function shopCommentList() {
        $shopId = $this->request->get('shopid');
        $type = $this->request->get('type');
        $result = PublicBusiness::commentList($shopId, $type);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $lists = $result['data'];
        $data = ['lists'=>$lists];
        return view('mobile.today.comment_list', $data);
    }
    //地图
    public function shopMap() {
        $shopId = $this->request->get('shopid');
        $address = $this->request->get('address');
        $name = $this->request->get('name');
        $data = [
            'shopid' => $shopId,
            'address' => $address,
            'name' => $name
        ];
        return view('mobile.today.map', $data);
    }
    //搜索商家
    public function searchShop() {
        if($this->request->has('cityid')) {
            $cityId = $this->request->get('cityid');
        } else {
            $cityId = 1; //默认为南昌
        }
        $globalSearch = [];
        $result = PublicBusiness::getHotWordList($cityId);
        if($result['status'] == 'success') {
            $lists = $result['data'];
            foreach($lists as $list) {
                array_push($globalSearch, $list['name']);
            }
        }
        //$globalSearch = ["美发","KTV","串串","火锅","花店","酒店","烤全羊","万达"];
        if(Cookie::has('search_array')) {
            $selfSearch = Cookie::get('search_array');
        } else {
            $selfSearch = [];
        }
        $data = [
            'globalsearch' => $globalSearch,
            'selfsearch' => $selfSearch
        ];

        return view('mobile.today.search_shop', $data);
    }
    //搜索商家结果
    public function searchShopResult() {
        if(!Cookie::has('cityid')){
            //获取城市id
            if($this->request->has('cityid')) {
                $cityId = $this->request->get('cityid');
            } else {
                return redirect()->to('/mobile/position');
            }
        } else {
            $cityId = Cookie::get('cityid');
        }
        $myLongitude = '';
        $myLatitude = '';
        if(!$this->request->has('search')) {
            return redirect()->to('/mobile/shop/search');
        }
        $search = $this->request->get('search');
        $result = PublicBusiness::searchShop($cityId, $search, $myLongitude,$myLatitude);
        if($result['status'] == 'failed') {
            $lists = [];
        } else {
            $lists = $result['data'];
        }
        if(Cookie::has('search_array')) {
            $searchArray = Cookie::get('search_array');
        } else {
            $searchArray = [];
        }
        if(!in_array($search, $searchArray)) {
            array_push($searchArray, $search);
        }
        $data = [
            'lists' => $lists,
            'search' => $search,
            'mylongitude' => $myLongitude,
            'mylatitude' => $myLatitude,
            'cityid' => $cityId
        ];
        return response()->make(view('mobile.today.search_result', $data))->withCookie(cookie('search_array', $searchArray));
    }
    //清除搜索
    public function clearSearch() {
        $searchArray = [];
        return redirect()->to('/mobile/shop/search')->withCookie(cookie('search_array', $searchArray));;
    }
    //预告
    public function next() {
        //获取城市id
        if(Cookie::has('cityid')) {
            $cityId = Cookie::get('cityid');
        } else {
            if($this->request->has('cityid')) {
                $cityId = $this->request->get('cityid');
            } else {
                $cityId = 1; //默认城市
            }
        }
        if(Cookie::has('mylongitude')) {
            $myLongitude = Cookie::get('mylongitude');
        } else {
            if($this->request->has('mylongitude')) {
                $myLongitude = $this->request->get('mylongitude');
            } else {
                $myLongitude = "";
            }
        }
        if(Cookie::has('mylatitude')) {
            $myLatitude = Cookie::get('mylatitude');
        } else {
            if($this->request->has('mylatitude')) {
                $myLatitude = $this->request->get('mylatitude');
            } else {
                $myLatitude = "";
            }
        }
        //商家一级，二级分类
        $categoryResult = Common::getClass();
        if($categoryResult['status'] == 'failed') {
            return view('errors.404');
        }
        $categoryLists = $categoryResult['data'];
        //城市区县，商圈
        $areaResult = Common::getDistrictAndBusinessArea($cityId);
        if($areaResult['status'] == 'failed') {
            return view('errors.404');
        }
        $areaLists = $areaResult['data'];
        //获取商家列表
        $parameter = [];
        $event = 'next';
        $nextEvent = '';
        if($this->request->has('nextevent')) {
            $nextEvent = $this->request->get('nextevent');
            $parameter['nextevent'] = date('Y-m-d', strtotime($nextEvent));
        }
        if($this->request->has('classid')) {
            $classId = $this->request->get('classid');
        } else {
            $classId = '';
        }
        if($this->request->has('isfirstclass') && !empty($classId)) {
            $isFirstClass = $this->request->get('isfirstclass');
            if($isFirstClass == '1') {
                $parameter['firstclassid'] = $classId;
            } else {
                $parameter['secondclassid'] = $classId;
            }
        }
        if($this->request->has('districtid')) {
            $parameter['districtid'] = $this->request->get('districtid');
        }
        if($this->request->has('businessareaid')) {
            $parameter['businessareaid'] = $this->request->get('businessareaid');
        }
        if($this->request->has('classname')) {
            $className = $this->request->get('classname');
        } else {
            $className = "全部";
        }
        if($this->request->has('areaname')) {
            $areaName = $this->request->get('areaname');
        } else {
            $areaName = '全部';
        }
        if($this->request->has('sort')) {
            $sort = $this->request->get('sort');
        } else {
            $sort = 'distance';
        }
        $shopListResult = PublicBusiness::shopList($cityId,$event,$myLongitude,$myLatitude,$parameter,$sort);
        if($shopListResult['status'] == 'failed') {
            $shopLists = [];
        } else {
            $shopLists = $shopListResult['data'];
        }
        $tomorrow = date("Y-m-d", strtotime("+1day"));
        $beginDate=date('Y-m-01', strtotime(date("Y-m-d"))); //获取当前月份第一天
        $endDate = date('Y-m-d', strtotime("$beginDate +2 month -1 day")); //加一个月减去一天
        $data = [
            'categorylists' => $categoryLists,
            'arealists' => $areaLists,
            'shoplists' => $shopLists,
            'cityid' => $cityId,
            'mylongitude' => $myLongitude,
            'mylatitude' => $myLatitude,
            'tomorrow' => $tomorrow,
            'begindate' => $beginDate,
            'enddate' => $endDate,
            'nextevent' => $nextEvent,
            'classname' => $className,
            'areaname' => $areaName,
        ];
        return response()->make(view('mobile.today.next', $data))->withCookie(cookie('cityid', $cityId))
            ->withCookie(cookie('mylongitude', $myLongitude))->withCookie(cookie('mylatitude', $myLatitude));
    }
    //晚九点
    public function night() {
        //获取城市id
        if(Cookie::has('cityid')) {
            $cityId = Cookie::get('cityid');
        } else {
            if($this->request->has('cityid')) {
                $cityId = $this->request->get('cityid');
            } else {
                $cityId = 1; //默认城市
            }
        }
        if(Cookie::has('mylongitude')) {
            $myLongitude = Cookie::get('mylongitude');
        } else {
            if($this->request->has('mylongitude')) {
                $myLongitude = $this->request->get('mylongitude');
            } else {
                $myLongitude = "";
            }
        }
        if(Cookie::has('mylatitude')) {
            $myLatitude = Cookie::get('mylatitude');
        } else {
            if($this->request->has('mylatitude')) {
                $myLatitude = $this->request->get('mylatitude');
            } else {
                $myLatitude = "";
            }
        }
        //商家一级，二级分类
        $categoryResult = Common::getNightEventClass();
        if($categoryResult['status'] == 'failed') {
            return view('errors.404');
        }
        $categoryLists = $categoryResult['data'];
        //城市区县，商圈
        $areaResult = Common::getDistrictAndBusinessArea($cityId);
        if($areaResult['status'] == 'failed') {
            return view('errors.404');
        }
        $areaLists = $areaResult['data'];
        //获取商家列表
        $event = 'occur';
        if($this->request->has('classid')) {
            $classId = $this->request->get('classid');
        } else {
            $classId = '';
        }
        if($this->request->has('isfirstclass') && !empty($classId)) {
            $isFirstClass = $this->request->get('isfirstclass');
            if($isFirstClass == '1') {
                $parameter['firstclassid'] = $classId;
            } else {
                $parameter['secondclassid'] = $classId;
            }
        }
        if($this->request->has('districtid')) {
            $parameter['districtid'] = $this->request->get('districtid');
        }
        if($this->request->has('businessareaid')) {
            $parameter['businessareaid'] = $this->request->get('businessareaid');
        }
        if($this->request->has('sort')) {
            $sort = $this->request->get('sort');
        } else {
            $sort = 'distance';
        }
        $shopListResult = PublicBusiness::shopList($cityId,$event,$myLongitude,$myLatitude,$parameter,$sort);
        if($shopListResult['status'] == 'failed') {
            $shopLists = [];
        } else {
            $shopLists = $shopListResult['data'];
        }
        $data = [
            'categorylists' => $categoryLists,
            'arealists' => $areaLists,
            'shoplists' => $shopLists,
            'cityid' => $cityId,
            'mylongitude' => $myLongitude,
            'mylatitude' => $myLatitude
        ];
        return view('mobile.today.night', $data);
    }
    //获取城市id， 经纬度
    public function getCityAndLongitudeAndLatitude() {
        //获取城市id
        if(Cookie::has('cityid')) {
            $cityId = Cookie::get('cityid');
        } else {
            if($this->request->has('cityid')) {
                $cityId = $this->request->get('cityid');
            } else {
                $cityId = 1; //默认城市
            }
        }
        if(Cookie::has('mylongitude')) {
            $myLongitude = Cookie::get('mylongitude');
        } else {
            if($this->request->has('mylongitude')) {
                $myLongitude = $this->request->get('mylongitude');
            } else {
                $myLongitude = "";
            }
        }
        if(Cookie::has('mylatitude')) {
            $myLatitude = Cookie::get('mylatitude');
        } else {
            if($this->request->has('mylatitude')) {
                $myLatitude = $this->request->get('mylatitude');
            } else {
                $myLatitude = "";
            }
        }
        $data = [
            'cityid' => $cityId,
            'mylongitude' => $myLongitude,
            'mylatitude' => $myLatitude
        ];
        return ['status'=>'success', 'data'=>$data];
    }
    //404页面
    public function error() {
        return view('errors.404');
    }
    //忘记密码
    public function bannerTest() {
        return view('mobile.today.banner_test');
    }
}